//点击选择地址时出现地址选择框
$(".choose").click(function () {
    $(".ui-sheet").slideDown();
});
//点击请选择出现省市县列表
$(".ui-sheet .second .sheng").click(function () {
    $(this).parent().find("span").css({"display": "none"});
    $(this).css({"display": "inline-block"}).addClass("active");
    $(".ui-sheet .address_details .province").css({"display": "block"});
    $(".ui-sheet .address_details .city").css({"display": "none"});
    $(".ui-sheet .address_details .county").css({"display": "none"});
    $(this).text("请选择省");
    $(".ui-sheet .second .shi").text("请选择市");
    $(".ui-sheet .second .xian").text("请选择县");
});
$(".ui-sheet .second .shi").click(function () {
    $(".ui-sheet .second .xian").css({"display": "none"});
    $(this).siblings().removeClass("active");
    $(this).addClass("active");
    $(".ui-sheet .address_details .province").css({"display": "none"});
    $(".ui-sheet .address_details .city").css({"display": "block"});
    $(".ui-sheet .address_details .county").css({"display": "none"});
    $(this).text("请选择市");
    $(".ui-sheet .second .xian").text("请选择县");
});
//点击列表内容选择省市县
var a, b, c;
$(document).on("click", ".ui-sheet .address_details .province .item", function () {
    $(".ui-sheet .address_details .province").css({"display": "none"});
    $(".ui-sheet .address_details .city").css({"display": "block"});
    $(this).parent().find("li").removeClass("active");
    $(this).addClass("active");
    a = $(this).find("span").attr("value");
    $(".ui-sheet .second .sheng").text($(this).text());
    $(".ui-sheet .second .sheng").removeClass("active");
    $(".ui-sheet .second .shi").css({"display": "inline-block"}).addClass("active");
    City();
});
$(document).on("click", ".ui-sheet .address_details .city .item", function () {
    $(".ui-sheet .address_details .city").css({"display": "none"});
    $(".ui-sheet .address_details .county").css({"display": "block"});
    $(this).parent().find("li").removeClass("active");
    $(this).addClass("active");
    b = $(this).find("span").attr("value");
    $(".ui-sheet .second .shi").text($(this).text());
    $(".ui-sheet .second .shi").removeClass("active");
    $(".ui-sheet .second .xian").css({"display": "inline-block"}).addClass("active");
    County();
});
$(document).on("click", ".ui-sheet .address_details .county .item", function () {
    $(".ui-sheet .second .xian").text($(this).text());
    County();
});
var Province = function () {
    $.ajax({
        url: "static/json/date.json",
        success: function (data) {
            var result = "";
            for (i = 0; i < data.ProvinceDate.length; i++) {
                result += "<li class='item'><span value='" + data.ProvinceDate[i].ProID + "'>" + data.ProvinceDate[i].ProName + "</span></li>";
            }
            $(".ui-sheet .address_details .province").append(result);
        },
        error: function () {
            alert("ajax请求失败");
        },
        complete: function (XMLHttpRequest, textStatus) {
            console.log(XMLHttpRequest.responseText);
            console.log(textStatus);
        }
    });
};
Province();
var City = function () {
    $.ajax({
        url: "static/json/date.json",
        success: function (data) {
            var result = "";
            for (i = 0; i < data.CityDate.length; i++) {
                if (data.CityDate[i].ProID === parseInt(a)) {
                    result += "<li class='item'><span value='" + data.CityDate[i].CityID + "'>" + data.CityDate[i].CityName + "</span></li>";
                }
            }
            $(".ui-sheet .address_details .city").children("li").remove();
            $(".ui-sheet .address_details .city").append(result);
        },
        error: function () {
            alert("ajax请求失败");
        },
        complete: function (XMLHttpRequest, textStatus) {
            console.log(XMLHttpRequest.responseText);
            console.log(textStatus);
        }
    });
};
var County = function () {
    $.ajax({
        url: "static/json/date.json",
        success: function (data) {
            var result = "";
            for (i = 0; i < data.CountyDate.length; i++) {
                if (data.CountyDate[i].CityID === parseInt(b)) {
                    result += "<li class='item'><span value='" + data.CountyDate[i].Id + "'>" + data.CountyDate[i].DisName + "</span></li>";
                }
            }
            $(".ui-sheet .address_details .county").children("li").remove();
            $(".ui-sheet .address_details .county").append(result);
        },
        error: function () {
            alert("ajax请求失败");
        },
        complete: function (XMLHttpRequest, textStatus) {
            console.log(XMLHttpRequest.responseText);
            console.log(textStatus);
        }
    });
};
//点击取消/确定判断是否需要传出选择的地址
$(document).on("click", ".ui-sheet .address .remove", function () {
    $(".ui-sheet").fadeOut();
});
$(document).on("click", ".ui-sheet .address .ensure", function () {
    var str = $(".address .sheng").text() + $(".address .shi").text() + $(".address .xian").text();
    var reg = /.*[\u8bf7|\u9009|\u62e9].*/;
    if (reg.test(str)) {
        c = "请确认您的地址";
    } else {
        c = $(".address .sheng").text() + $(".address .shi").text() + $(".address .xian").text();
        $(".ui-sheet").fadeOut();
    }
    alert(c);
});